#include<iostream>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<cstring>
using namespace std;
char* Argv[20];

void get_cmd(char cmd[], int n)
{
    fgets(cmd,n,stdin);
    cmd[strlen(cmd) - 1] = '\0';
}

void ana_cmd(char cmd[])
{
    Argv[0] = strtok(cmd," ");
    int i = 1;
    while(Argv[i++] = strtok(NULL, " "));
}

void exe_cmd()
{
    pid_t id = fork();
    //子进程
    if(id == 0)
    {
        execvp(Argv[0],Argv);
    }
    //父进程
    else if(id > 0)
    {
        pid_t wd = waitpid(id, nullptr, 0);
    }
}

int main()
{
    cout << "myshell:>";
    //获取指令
    char cmd[128];
    get_cmd(cmd, sizeof(cmd));

    //解析指令
    ana_cmd(cmd);

    //执行指令
    exe_cmd();

    return 0;
}